package errcode

import (
	"net/http"
)

var (
	Success            = newError(0, "success")
	ErrServer          = newError(10000, "服务器内部错误")
	ErrParams          = newError(10001, "参数错误")
	ErrNotFound        = newError(10002, "资源未找到")
	ErrPanic           = newError(10003, "(*^__^*)系统开小差了,请稍后重试")
	ErrToken           = newError(10004, "Token无效")
	ErrForbidden       = newError(10005, "没有权限")
	ErrTooManyRequests = newError(10006, "请求过于频繁")
	ErrUserInvalid     = newError(10007, "用户异常")
)

func (e *AppError) HttpStatusCode() int {
	switch e.Code() {
	case Success.code:
		return http.StatusOK
	case ErrServer.Code(), ErrPanic.Code():
		return http.StatusInternalServerError
	case ErrParams.Code():
		return http.StatusBadRequest
	case ErrNotFound.Code():
		return http.StatusNotFound
	case ErrTooManyRequests.Code():
		return http.StatusTooManyRequests
	case ErrToken.Code():
		return http.StatusUnauthorized
	case ErrForbidden.Code():
		return http.StatusForbidden
	default:
		return http.StatusInternalServerError
	}
}
